import pygame
from pygame.sprite import Sprite

class Bullet(Sprite):
    '''管理子弹'''
    def __init__(self, ai_game):
        super().__init__()
        self.screen=ai_game.screen
        self.setting=ai_game.setting
        self.color=self.setting.bullet_color
        '''在（0,0）处创建一个子弹'''
        self.rect=pygame.Rect(0,0,self.setting.bullet_width,self.setting.bullet_height)
        self.rect.midtop=ai_game.ship.rect.midtop
        '''用小数表示子弹位置'''
        self.y=float(self.rect.y)
    def update(self):
        '''向上移动的子弹'''
        self.y-=self.setting.bullet_speed
        self.rect.y=self.y
    def draw_bullet(self):
         pygame.draw.rect(self.screen,self.color,self.rect)